import java.util.Vector;

public final class cls_ab
        implements Runnable {

    MainThread mainThread;
    cls_s b;
    cls_af c[];
    private Vector vector;
    private boolean h;
    boolean d;
    int e;
    int f;
    private Thread thread;

    public cls_ab(MainThread thread) {
        mainThread = thread;
        d = false;
        vector = new Vector();
        e = -1;
        b = new cls_o(this);
    }

    public final void run() {
        while (!vector.isEmpty()) {
            if (mainThread.aS) {
                thread = null;
                h = false;
                return;
            }
            int ai[];
            int k;
            cls_af af1;
            h = true;

            try {
                Thread.sleep(50L);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            ai = (int[]) vector.firstElement();
            k = ai[0];
            af1 = c[k];
            int j = ai[1];
            switch (j) {
                case 0:
                    if (c[k].c != 0)
                        b.a(af1);
                    break;
                case 1:
                case 2:
                    if (mainThread.recordManager.a && k > e) {
                        if (e != -1)
                            b.a(c[e]);
                        if (!b.b) {
                            e = k;
                            b.a(c[f], c[e]);
                            if (b.a(af1, j == 2)) {
                                f = k;
                                b.b = true;
                            } else {
                                b.e(c[e]);
                                e = -1;
                            }
                        }
                    }
                    break;
                case 3:
                    b.b(af1);
                    e = -1;
                    b.b = false;
                    break;
                case 4:
                    if (mainThread.recordManager.a) {
                        b.c(af1);
                        e = k;
                        b.b = true;
                    }
                    vector.removeElementAt(0);
                    break;
            }
        }
        thread = null;
        h = false;
    }

    final void a() {
        if (!vector.isEmpty())
            vector.removeAllElements();
    }

    final void b() {
        if (!h) {
            h = true;
            thread = new Thread(this);
            thread.start();
        }
    }

    final void c() {
        c = new cls_af[inf_r.ah.length];
        for (int j = 0; j < c.length; j++) {
            if (inf_r.ah[j] != -1)
                c[j] = b.a(inf_r.ah[j]);
            mainThread.a();
        }

    }

    final void a(int j, boolean flag) {
        if (mainThread.recordManager.a && c[j] != null) {
            vector.addElement(new int[]{j, flag ? 2 : 1});
            b();
        }
    }

    final void a(int j) {
        a(j, false);
    }

    final void b(int j) {
        if (c[j] != null) {
            vector.addElement(new int[]{j, 0});
            b();
        }
    }

    final void d() {
        if (c != null) {
            for (int j = 0; j < c.length; j++)
                if (c[j] != null && (c[j].c == 2 || c[j].c == 1))
                    b.a(c[j]);

            e = -1;
            b.b = false;
            try {
                Thread.sleep(200L);
            }
            catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}